<?php

namespace App\Models\Encyclopedia;

use App\Ant\WithAuthor;
use App\Models\Media;
use Illuminate\Database\Eloquent\Model;

class Article extends Model
{
    use WithAuthor;

    protected $table = 'encyclopedia_article';

    protected $fillable = [
        'author_id',
        'title',
        'guide',
        'category_id',
        'media_id'
    ];

    protected $casts = [
        'status' => 'boolean'
    ];

    public function category()
    {
        return $this->hasOne(Category::class, 'id', 'category_id');
    }

    public function content()
    {
        return $this->hasOne(ArticleContent::class, 'article_id', 'id');
    }

    public function media()
    {
        return $this->hasOne(Media::class, 'id', 'media_id');
    }

    public function scopeDesign($query, $category_id = null)
    {
        return $query->where('category_id', $category_id);
    }
}
